﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using OSISDynamicTranslation;
using OSISToolTip;
using AjaxControlToolkit;
using OpenSISStudentListControl;
using OpenSIS.OpenSISWCFServiceReference;
using OpenSISInstall;

namespace OpenSIS.Student
{
    public partial class StudentInfo : System.Web.UI.Page
    {
        static string AddTableList = "";
        DropDownList ddlSchoolName = new DropDownList();
        DropDownList ddlFullYear = new DropDownList();
        DropDownList ddlLevel1 = new DropDownList();
        TooltipLang TTL = new TooltipLang();
        private HtmlTableRow dTRow;
        private HtmlTableCell dTCell;
        private HtmlTableRow dTAddRow;
        private HtmlTableCell dTAddCell;
        private HtmlTableCell dTAddCell1;
        private HtmlTableCell dTAddCell2;
        private HtmlTableCell dTCell1;
        private HtmlTableCell dTCell2;
        private HtmlTableCell dTAdditionalContCell;
        private HtmlTableCell dTAdditionalContCell1;
        private HtmlTableCell dTAdditionalContCell2;
        private HtmlTableRow dTAdditionalContRow;
        private HtmlTable dTAdd;
        DataRow drvacc;
        private static string langto;
        DynamicTranslation DTL = new DynamicTranslation();

        protected void Page_Load(object sender, EventArgs e)
        {
            langto = Session["MLUICulture"].ToString();
            TTL.tooltip();
            ibtnView.Attributes.Add("onmouseover", "toolTip('" + TTL.View + "')");
            ibtnView.Attributes.Add("onmouseout", "toolTip()");
            ibtnView.Attributes.Add("onclick", "toolTip('');return true;");
            ibtnEdit.Attributes.Add("onmouseover", "toolTip('" + TTL.Edit + "')");
            ibtnEdit.Attributes.Add("onmouseout", "toolTip()");
            ibtnEdit.Attributes.Add("onclick", "toolTip('');return true;");
            ibtnDelete.Attributes.Add("onmouseover", "toolTip('" + TTL.Delete + "')");
            ibtnDelete.Attributes.Add("onmouseout", "toolTip()");
            ibtnDelete.Attributes.Add("onclick", "toolTip('');return true;");
            PopulateMLUI();
            if (!Page.IsPostBack)
            {
                mvMain.ActiveViewIndex = 0;
                mvFormLayout.ActiveViewIndex = 1;
                PopulateControls();//populates the dropdowns in the search box
                PopulateStudentListGrid();    
            }
            PopulateStudent360Tree();
            PopulateCategoryTree();

            SISInstall SISInstall = new SISInstall();
            OpenSISWCFServiceInstallationClient OSISinstallClient = new OpenSISWCFServiceInstallationClient();

            DataTable dtDateFormat = OSISinstallClient.getdateformat();
            OSISinstallClient.Close();

            if (dtDateFormat.Rows.Count > 0)
            {
                SISInstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
            }

            CalenderPicker.Format = SISInstall.CalenderDateFormat.ToString().Trim();
        }
        protected void PopulateControls()
        {
            StudentListControl StdInfo = new StudentListControl();
            StdInfo.populateEthnicity(ref ddlEthnicity, Convert.ToInt32(Session["SchoolID"]));
            StdInfo.PopulateGenderSearch(ref ddlGender);
        }
        protected void PopulateStudentListGrid()
        {
            OpenSISWCFServiceStudentInformationClient stinfo = new OpenSISWCFServiceStudentInformationClient();
            try
            {                
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                DataTable dt = stinfo.populatestudentlistbyschoolid(SchoolID,"","","","","","","");
                stinfo.Close();
                gvStudentList.DataSource = dt;
                gvStudentList.DataBind();
            }
            catch { }
            finally
            {
                stinfo = null;
            }
        }
        public void PopulateStudent360Tree()
        {
            try
            {
                tvStudent360.Nodes.Clear();
                TreeNode TreeNodeDashboard = new TreeNode();
                //TreeNodeDashboard.Text = "Dashboard";
                string stringToTranslate = "Dashboard";
                string translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeDashboard.Text = translatedString;
                TreeNodeDashboard.Value = Convert.ToString("0");
                TreeNodeDashboard.ImageUrl = "~/App_Themes/main/images/icon_dashboard.png";
                tvStudent360.Nodes.Add(TreeNodeDashboard);
                TreeNode TreeNodeGeneralInfo = new TreeNode();
                stringToTranslate = "General Info";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeGeneralInfo.Text = translatedString;
                //TreeNodeGeneralInfo.Text = "General Info";
                TreeNodeGeneralInfo.Value = Convert.ToString("1");
                TreeNodeGeneralInfo.ImageUrl = "~/App_Themes/main/images/icon_generalinfo.png";
                tvStudent360.Nodes.Add(TreeNodeGeneralInfo);
                TreeNode TreeNodeAttendance = new TreeNode();
                stringToTranslate = "Attendance";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeAttendance.Text = translatedString;
                //TreeNodeAttendance.Text = "Attendance";
                TreeNodeAttendance.Value = Convert.ToString("2");
                TreeNodeAttendance.ImageUrl = "~/App_Themes/main/images/icon_attendance.png";
                tvStudent360.Nodes.Add(TreeNodeAttendance);
                TreeNode TreeNodeSchedule = new TreeNode();
                stringToTranslate = "Schedule";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeSchedule.Text = translatedString;
                //TreeNodeSchedule.Text = "Schedule";
                TreeNodeSchedule.Value = Convert.ToString("3");
                TreeNodeSchedule.ImageUrl = "~/App_Themes/main/images/icon_schedule.png";
                tvStudent360.Nodes.Add(TreeNodeSchedule);
                TreeNode TreeNodeGrades = new TreeNode();
                stringToTranslate = "Grades";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeGrades.Text = translatedString;
                //TreeNodeGrades.Text = "Grades";
                TreeNodeGrades.Value = Convert.ToString("4");
                TreeNodeGrades.ImageUrl = "~/App_Themes/main/images/icon_grades.png";
                tvStudent360.Nodes.Add(TreeNodeGrades);
                TreeNode TreeNodeEligibility = new TreeNode();
                stringToTranslate = "Eligibility";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeEligibility.Text = translatedString;
                //TreeNodeEligibility.Text = "Eligibility";
                TreeNodeEligibility.Value = Convert.ToString("5");
                TreeNodeEligibility.ImageUrl = "~/App_Themes/main/images/icon_eligibility.png";
                tvStudent360.Nodes.Add(TreeNodeEligibility);
                TreeNode TreeNodeDiscipline = new TreeNode();
                stringToTranslate = "Discipline";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeDiscipline.Text = translatedString;
                //TreeNodeDiscipline.Text = "Discipline";
                TreeNodeDiscipline.Value = Convert.ToString("6");
                TreeNodeDiscipline.ImageUrl = "~/App_Themes/main/images/icon_discipline.png";
                tvStudent360.Nodes.Add(TreeNodeDiscipline);
                TreeNode TreeNodeBilling = new TreeNode();
                stringToTranslate = "Billing";
                translatedString = DTL.Translate(stringToTranslate, "en", langto);
                TreeNodeBilling.Text = translatedString;
                //TreeNodeBilling.Text = "Billing";
                TreeNodeBilling.Value = Convert.ToString("7");
                TreeNodeBilling.ImageUrl = "~/App_Themes/main/images/icon_billing.png";
                tvStudent360.Nodes.Add(TreeNodeBilling);
                tvStudent360.ExpandAll();
            }
            catch { }
        }
        public void PopulateCategoryTree()
        {
            OpenSISWCFServiceStudentSetupClient schoolcategory = new OpenSISWCFServiceStudentSetupClient();
            try
            {
               int SchoolId = Convert.ToInt32(Session["SchoolID"]);
               DataTable dt = schoolcategory.GetSchoolSpecificCategory(SchoolId.ToString(), Session["MLUICulture"].ToString());
               schoolcategory.Close();
                tvCategoryList.Nodes.Clear();
                string[,] CategoryData = new string[100, 4];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeNode TreeNodeCategory = new TreeNode();
                    CategoryData[i, 0] = dt.Rows[i]["Cat_Name"].ToString();
                    CategoryData[i, 1] = dt.Rows[i]["Cat_Id"].ToString();
                    TreeNodeCategory.Text = CategoryData[i, 0];
                    TreeNodeCategory.Value = CategoryData[i, 1];
                    tvCategoryList.Nodes.Add(TreeNodeCategory);
                    tvCategoryList.ExpandAll();
                }
            }
            catch { }
            finally
            {
                schoolcategory = null;
            }
        }
        protected void tvStudent360_SelectedNodeChanged(object sender, EventArgs e)
        {
            //StudentInfoBL StdInfo = new StudentInfoBL();
            try
            {
                mvFormLayout.ActiveViewIndex = Convert.ToInt32(tvStudent360.SelectedNode.Value);
                if (Convert.ToInt32(tvStudent360.SelectedNode.Value) == 1)
                {
                    int StudentID = Convert.ToInt32(hdnStdId.Value);
                    int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    int CatId = 1;
                    OpenSISWCFServiceStudentInformationClient StdInfoFVBC = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dt = StdInfoFVBC.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                    rptrFields.DataSource = dt;
                    rptrFields.DataBind();
                    tvCategoryList.Nodes[0].Selected = true;
                    tvStudent360.Nodes[1].Selected = true;
                }
                else
                {
                    //rptrFields.DataSource = null;
                    //rptrFields.DataBind();
                }
                phAllFieldHolder.Controls.Clear();
            }
            catch { }
        }        
        protected void rptrSummary_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
           
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);         
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            Label lblValue = (Label)e.Item.FindControl("lblValue");
            if (hdnFieldId.Value == "13")
            {
                hdnDOB.Value = lblValue.Text.ToString();
            }
            if (hdnFieldId.Value == "13")//DOB and Age
            {
                if (hdnDOB.Value != "")
                {
                    DateTime d = DateTime.Parse(hdnDOB.Value.ToString());
                    int age = DateTime.Now.Year - d.Year;
                    if (DateTime.Now.Month < d.Month || (DateTime.Now.Month == d.Month && DateTime.Now.Day < d.Day))
                        age--;
                    lblValue.Text = lblValue.Text.ToString() + " | " + age.ToString();
                }
            }
            if (hdnFieldId.Value == "11")//ETHNICITY
            {
                if (lblValue.Text.ToString() != "")
                {
                    int EthnicityId = Convert.ToInt32(lblValue.Text);

                    OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtethnicity = StdInfo.getethnicity(EthnicityId);
                    StdInfo.Close();

                    if (dtethnicity.Rows.Count > 0)
                    {
                        lblValue.Text = dtethnicity.Rows[0]["eth_nm"].ToString();
                    }
                    if (lblValue.Text == "0")
                    {
                        lblValue.Text = "";
                    }
                }
            }
            if (hdnFieldId.Value == "15")//PRIMARY LANGUAGE
            {
                if (lblValue.Text.ToString() != "")
                {
                    int Language = Convert.ToInt32(lblValue.Text);
                    OpenSISWCFServiceStudentInformationClient StdInfoGE = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtlanguage = StdInfoGE.getlanguage(Language);
                    StdInfoGE.Close();

                    if (dtlanguage.Rows.Count > 0)
                    {
                        lblValue.Text = dtlanguage.Rows[0]["language_nm"].ToString();
                    }
                    if (lblValue.Text == "0")
                    {
                        lblValue.Text = "";
                    }
                }
            }
            if (hdnFieldId.Value == "110")//CALENDER
            {
                if (lblValue.Text.ToString() != "")
                {
                    string Calender = lblValue.Text.ToString();

                    OpenSISWCFServiceStudentInformationClient StdInfoGE = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtcalender = StdInfoGE.getcalendername(Calender,SchoolID);
                    StdInfoGE.Close();

                    if (dtcalender.Rows.Count > 0)
                    {
                        lblValue.Text = dtcalender.Rows[0]["Calender_Name"].ToString();
                    }
                    if (lblValue.Text == "0")
                    {
                        lblValue.Text = "";
                    }
                }
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            OpenSISWCFServiceStudentInformationClient stinfo = new OpenSISWCFServiceStudentInformationClient();
            try
            {
                string FName = txtFName.Text.ToString().Trim();
                string LName = txtLName.Text.ToString().Trim();
                string Gender = ddlGender.SelectedItem.Value;
                string Ethnicity = ddlEthnicity.SelectedItem.Value;
                string DOB = txtDOB.Text.ToString().Trim();
                string EnrollmentDate = txtEnrollmentDate.Text.ToString().Trim();
                string StdSchId = txtStdSchId.Text.ToString().Trim();
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                DataTable dt = stinfo.populatestudentlistbyschoolid(SchoolID,FName,LName,Gender,Ethnicity,DOB,EnrollmentDate,StdSchId);
                stinfo.Close();
                gvStudentList.DataSource = dt;
                gvStudentList.DataBind();
            }
            catch { }
            finally
            {
                stinfo = null;
            }
        }
        protected void ibtnView_Click(object sender, ImageClickEventArgs e)
        {
            OpenSISWCFServiceStudentInformationClient StdInfo = new OpenSISWCFServiceStudentInformationClient();
            for (int i = 0; i < gvStudentList.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)gvStudentList.Items[i].FindControl("chk");
                HiddenField hdnStudentId = (HiddenField)gvStudentList.Items[i].FindControl("hdnStudentId");
                if (chk.Checked)
                {
                    int StudentID = Convert.ToInt32(hdnStudentId.Value);
                    hdnStdId.Value = hdnStudentId.Value;
                    int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    int CatId = 1;

                    DataTable dt = StdInfo.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                    StdInfo.Close();
                    rptrFields.DataSource = dt;
                    rptrFields.DataBind();
                    tvCategoryList.Nodes[0].Selected = true;
                    tvStudent360.Nodes[1].Selected = true;
                    lblHeader.Visible = true;
                    lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                    PopulateSummaryFields();
                    lblstudentNo.Text = (i + 1).ToString();
                    lblTotalStudentOfSchool.Text = (gvStudentList.Items.Count).ToString();
                    if (lblstudentNo.Text == lblTotalStudentOfSchool.Text)
                    {
                        lbtnLastStudent.Enabled = false;
                        lbtnNextStudent.Enabled = false;
                    }
                    if (lblstudentNo.Text == "1")
                    {
                        lbtnPreviousStudent.Enabled = false;
                        lbtnFirstStudent.Enabled = false;
                    }
                    mvMain.ActiveViewIndex = 1;
                }
            }
        }
        protected void PopulateSummaryFields()
        {
            try
            {                
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                OpenSISWCFServiceStudentInformationClient StdInfoS = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfoS.GetSummaryFieldsStudentInfo(StudentID, Session["MLUICulture"].ToString());
                StdInfoS.Close();

                //=============================================
                DataRow dr1 = dt.NewRow();
                dr1["field_name"] = "Attendance Status";
                dt.Rows.Add(dr1);
                DataRow dr2 = dt.NewRow();
                dr2["field_name"] = "Current Location";
                dt.Rows.Add(dr2);
                DataRow dr3 = dt.NewRow();
                dr3["field_name"] = "With Whom";
                dt.Rows.Add(dr3);
                DataRow dr4 = dt.NewRow();
                dr4["field_name"] = "Med Alert";
                dt.Rows.Add(dr4);
                //=============================================
                rptrSummary.DataSource = dt;
                rptrSummary.DataBind();

                OpenSISWCFServiceStudentInformationClient StdInfoSh = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtsummaryheader = StdInfoSh.GetSummaryHeaderFields(StudentID, Session["MLUICulture"].ToString());
                StdInfoSh.Close();

                lblNameValue.Text = dtsummaryheader.Rows[0]["value"].ToString() + " " + dtsummaryheader.Rows[1]["value"].ToString() + " " + dtsummaryheader.Rows[2]["value"].ToString();
                lblGradeValue.Text = dtsummaryheader.Rows[3]["value"].ToString();
                lblHomeRoomValue.Text = dtsummaryheader.Rows[4]["value"].ToString();

                OpenSISWCFServiceStudentInformationClient StdInfoGPU = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtphoto = StdInfoGPU.GetPhotoURL(SchoolID,StudentID);
                StdInfoGPU.Close();
                
                if (dtphoto.Rows.Count > 0)
                {
                    divPhoto.Style.Add("background-image", "url(" + dtphoto.Rows[0]["name"].ToString() + ")");
                }
                else
                {
                    divPhoto.Style.Add("background-image", "url(../App_Themes/main/images/no_pic.png)");
                }

            }
            catch { }
        }
        protected void rptrFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            
            try
            {                
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                Label lblFieldName = (Label)e.Item.FindControl("lblFieldName");
                HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
                HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
                HiddenField hdnCatId = (HiddenField)e.Item.FindControl("hdnCatId");
                Repeater rptrAddressFields = (Repeater)e.Item.FindControl("rptrAddressFields");
                Label lblValue = (Label)e.Item.FindControl("lblValue");
                int FieldId = Convert.ToInt32(hdnFieldId.Value);
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                if (hdnDefCus.Value.ToString().Trim() == "D")
                {
                    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 5 || Convert.ToInt32(hdnFieldId.Value) == 7 || Convert.ToInt32(hdnFieldId.Value) == 109 || Convert.ToInt32(hdnFieldId.Value) == 174 || Convert.ToInt32(hdnFieldId.Value) == 6)
                    {
                        e.Item.Visible = false;
                    }
                    if (Convert.ToInt32(hdnFieldId.Value) == 10)//GENDER
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            string Gender = lblValue.Text.ToString();

                            OpenSISWCFServiceStudentInformationClient StdInfoGG = new OpenSISWCFServiceStudentInformationClient();
                            DataTable dtgender = StdInfoGG.getgender(Gender);
                            StdInfoGG.Close();


                            if (dtgender.Rows.Count > 0)
                            {
                                lblValue.Text = dtgender.Rows[0]["gender_nm"].ToString();
                            }
                        }
                    }
                    if (Convert.ToInt32(hdnFieldId.Value) == 16)//Secondary language
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            int Language = Convert.ToInt32(lblValue.Text);

                            OpenSISWCFServiceStudentInformationClient StdInfoGL = new OpenSISWCFServiceStudentInformationClient();
                            DataTable dtlanguage = StdInfoGL.getlanguage(Language);
                            StdInfoGL.Close();

                            if (dtlanguage.Rows.Count > 0)
                            {
                                lblValue.Text = dtlanguage.Rows[0]["language_nm"].ToString();
                            }
                        }
                    }
                    if (Convert.ToInt32(hdnFieldId.Value) == 18)//CITIZENSHIP
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            int CountryCode = Convert.ToInt32(lblValue.Text);

                            OpenSISWCFServiceStudentInformationClient StdInfoC = new OpenSISWCFServiceStudentInformationClient();
                            DataTable dtcitizenship = StdInfoC.getcountry(CountryCode);
                            StdInfoC.Close();
                            
                            if (dtcitizenship.Rows.Count > 0)
                            {
                                lblValue.Text = dtcitizenship.Rows[0]["NAME"].ToString();
                            }
                        }
                    }
                    if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            string StartCondition = lblValue.Text.ToString();

                         OpenSISWCFServiceStudentInformationClient StdInfoGSC = new OpenSISWCFServiceStudentInformationClient();

                         DataTable dtstartcdn = StdInfoGSC.getstartcondition(StartCondition);
                         StdInfoGSC.Close();

                            if (dtstartcdn.Rows.Count > 0)
                            {
                                lblValue.Text = dtstartcdn.Rows[0]["enr_cd_nm"].ToString();
                            }
                        }
                    }
                }
                else if (hdnDefCus.Value.ToString().Trim() == "C")
                {
                    OpenSISWCFServiceStudentInformationClient StdInfoGCT = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtfieldtype = StdInfoGCT.getcontroltype(FieldId);
                    StdInfoGCT.Close();

                    if (dtfieldtype.Rows[0]["field_type_id"].ToString() == "2" || dtfieldtype.Rows[0]["field_type_id"].ToString() == "3" || dtfieldtype.Rows[0]["field_type_id"].ToString() == "4")
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            int ListItemId = Convert.ToInt32(lblValue.Text);
                            OpenSISWCFServiceStudentInformationClient StdInfoGCLN = new OpenSISWCFServiceStudentInformationClient();
                            DataTable dtlistitemname = StdInfoGCLN.getcustomlistitemname(ListItemId);
                            StdInfoGCLN.Close();
                            
                            if (dtlistitemname.Rows.Count > 0)
                            {
                                lblValue.Text = dtlistitemname.Rows[0]["ListItem_name"].ToString();
                            }
                            if (lblValue.Text == "0")
                            {
                                lblValue.Text = "Select";
                            }
                        }
                    }
                }
            }
            catch { }
        }
        protected void tvCategoryList_SelectedNodeChanged(object sender, EventArgs e)
        {
           // StudentInfoBL StdInfo = new StudentInfoBL();
            int CatId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStdId.Value);
            hdnCatId.Value = tvCategoryList.SelectedNode.Value.ToString();
            if (tvCategoryList.SelectedNode.Value != "3")
            {
                if (tvCategoryList.SelectedNode.Value != "5")
                {
                    if (tvCategoryList.SelectedNode.Value != "4")
                    {
                        if (tvCategoryList.SelectedNode.Value != "8")
                        {
                          OpenSISWCFServiceStudentInformationClient StdInfoGFVC = new OpenSISWCFServiceStudentInformationClient();
                            DataTable dt = StdInfoGFVC.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                            StdInfoGFVC.Close();
                            rptrFields.DataSource = dt;
                            rptrFields.DataBind();
                            lblHeader.Visible = true;
                            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                            dtMedicalInfo.Visible = false;
                            rptrFields.Visible = true;
                            tblProgram.Visible = false;
                            rptrSchlInfo.Visible = false;
                            gvEnrInfo.Visible = false;
                            tblSchEnrInfo.Visible = false;
                            //rptrAddress.DataSource = null;
                            //rptrAddress.DataBind();
                        }
                        else
                        {
                            dtMedicalInfo.Visible = false;
                            rptrFields.Visible = false;
                            lblHeader.Visible = true;
                            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                            lblinnerheadSpec.Text = "<div class='heading_bevelline'> Special Education </div>" + "<div class='clear_m'>" + " " + "</div>";
                            lblInnerHeadGift.Text = "<div class='heading_bevelline'>Gifted Programmes</div>" + "<div class='clear_m'>" + " " + "</div>";
                            rptrSchlInfo.Visible = false;
                            gvEnrInfo.Visible = false;
                            tblSchEnrInfo.Visible = false;
                            tblProgram.Visible = true;
                            PopulateSpecialValue();
                            PopulateGiftValue();
                        }
                    }
                    else
                    {
                        dtMedicalInfo.Visible = false;
                        rptrFields.Visible = true;
                        tblProgram.Visible = false;

                        OpenSISWCFServiceStudentInformationClient StdInfoGFVC1 = new OpenSISWCFServiceStudentInformationClient();
                        DataTable dt = StdInfoGFVC1.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                        StdInfoGFVC1.Close();

                        rptrSchlInfo.DataSource = dt;
                        rptrSchlInfo.DataBind();
                        lblHeader.Visible = false;

                        OpenSISWCFServiceStudentInformationClient StdInfoGSCE = new OpenSISWCFServiceStudentInformationClient();
                        DataTable dtenrol = StdInfoGSCE.Getstudentschoolenroll(StudentID,SchoolID);
                        StdInfoGSCE.Close();

                        gvEnrInfo.DataSource = dtenrol;
                        gvEnrInfo.DataBind();
                        rptrFields.Visible = false;
                        gvEnrInfo.Visible = true;
                        tblSchEnrInfo.Visible = true;
                        rptrSchlInfo.Visible = true;
                    }
                }
                else
                {
                    tblProgram.Visible = false;

                    OpenSISWCFServiceStudentInformationClient StdInfoGMIFV = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtMediInfo = StdInfoGMIFV.GetMedicalInfoFieldValue(SchoolID, StudentID);
                    StdInfoGMIFV.Close();

                    rptMedicalInfo.DataSource = dtMediInfo;
                    rptMedicalInfo.DataBind();

                    OpenSISWCFServiceStudentInformationClient StdInfoGIFV = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtImmu = StdInfoGIFV.GetImmunizationFieldValue(SchoolID,StudentID);
                    StdInfoGIFV.Close();

                    GVImmunization.DataSource = dtImmu;
                    GVImmunization.DataBind();

                    OpenSISWCFServiceStudentInformationClient StdInfoGMAFV = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtAlert = StdInfoGMAFV.GetMedicalAlertFieldValue(StudentID);
                    StdInfoGMAFV.Close();

                    GVMedicalAlert.DataSource = dtAlert;
                    GVMedicalAlert.DataBind();

                    OpenSISWCFServiceStudentInformationClient StdInfoGNVFV = new OpenSISWCFServiceStudentInformationClient();
                    DataTable dtNurseVisit = StdInfoGNVFV.GetNurseVisitFieldValue(SchoolID,StudentID);
                    StdInfoGNVFV.Close();

                    GVNurseVisitRec.DataSource = dtNurseVisit;
                    GVNurseVisitRec.DataBind();
                    //DataTable dtVaccination = PopulateVacciGrid();
                    //GVVccination.DataSource = dtVaccination;
                    //GVVccination.DataBind();

                    //**************06/05/2010******
                    PopulateVccinationValue();
                    //***********************
                    lblHeader.Visible = true;
                    lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                    dtMedicalInfo.Visible = true;
                    rptrFields.Visible = false;
                    rptrSchlInfo.Visible = false;
                    gvEnrInfo.Visible = false;
                    tblSchEnrInfo.Visible = false;
                }
            }
            else
            {
                tblProgram.Visible = false;
                PopulateInSelectedNodeChange();
                PopulateFieldData();
                rptrFields.DataSource = null;
                rptrFields.DataBind();
                lblHeader.Text = "";
                rptrSchlInfo.Visible = false;
                gvEnrInfo.Visible = false;
                tblSchEnrInfo.Visible = false;
            }

            tvStudent360.Nodes[1].Selected = true;
            mvMain.ActiveViewIndex = 1;
            //mvFormLayout.ActiveViewIndex = 2;
        }

        protected void lbtnNextStudent_Click(object sender, EventArgs e)
        {
            try
            {
                lbtnFirstStudent.Enabled = true;
                lbtnPreviousStudent.Enabled = true;
                //StudentInfoBL StdInfo = new StudentInfoBL();
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                OpenSISWCFServiceStudentInformationClient StdInfoN = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfoN.GetNextStudentId(SchoolID,StudentID);
                StdInfoN.Close();
                hdnStdId.Value = dt.Rows[0]["std_id"].ToString();
                int studentno = Convert.ToInt32(lblstudentNo.Text);
                lblstudentNo.Text = Convert.ToString(studentno + 1);
                StudentID = Convert.ToInt32(hdnStdId.Value);
                int CatId = 1;
                OpenSISWCFServiceStudentInformationClient StdInform = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtmainfields = StdInform.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                StdInform.Close();
                rptrFields.DataSource = dtmainfields;
                rptrFields.DataBind();
                tvCategoryList.Nodes[0].Selected = true;
                tvStudent360.Nodes[1].Selected = true;
                lblHeader.Visible = true;
                lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                PopulateSummaryFields();
                if ((Convert.ToInt32(lblstudentNo.Text)) == (Convert.ToInt32(lblTotalStudentOfSchool.Text)))
                {
                    lbtnNextStudent.Enabled = false;
                    lbtnLastStudent.Enabled = false;
                }
                mvFormLayout.ActiveViewIndex = 1;
            }
            catch { }
        }
        protected void lbtnPreviousStudent_Click(object sender, EventArgs e)
        {
            try
            {
                lbtnNextStudent.Enabled = true;
                lbtnLastStudent.Enabled = true;
                
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                OpenSISWCFServiceStudentInformationClient StdInfoP = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfoP.GetPreviousStudentId(SchoolID,StudentID);
                StdInfoP.Close();
                hdnStdId.Value = dt.Rows[0]["std_id"].ToString();
                int studentno = Convert.ToInt32(lblstudentNo.Text);
                lblstudentNo.Text = Convert.ToString(studentno - 1);
                StudentID = Convert.ToInt32(hdnStdId.Value);
                int CatId = 1;
                OpenSISWCFServiceStudentInformationClient StdInform1 = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtmainfields = StdInform1.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());

                rptrFields.DataSource = dtmainfields;
                rptrFields.DataBind();
                tvCategoryList.Nodes[0].Selected = true;
                tvStudent360.Nodes[1].Selected = true;
                lblHeader.Visible = true;
                lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                PopulateSummaryFields();
                if (lblstudentNo.Text == "1")
                {
                    lbtnPreviousStudent.Enabled = false;
                    lbtnFirstStudent.Enabled = false;
                }
                mvFormLayout.ActiveViewIndex = 1;
            }
            catch { }
        }
        protected void lbtnFirstStudent_Click(object sender, EventArgs e)
        {
            try
            {
                lbtnLastStudent.Enabled = true;
                if (lblTotalStudentOfSchool.Text != "1")
                {
                    lbtnNextStudent.Enabled = true;
                }
                else
                {
                    lbtnNextStudent.Enabled = false;
                }
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                OpenSISWCFServiceStudentInformationClient StdInfoF = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfoF.GetFirstStudentIdBySchoolIId(SchoolID);
                StdInfoF.Close();

                hdnStdId.Value = dt.Rows[0]["std_id"].ToString();
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                int CatId = 1;
                OpenSISWCFServiceStudentInformationClient StdInfoFVC2 = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtmainfields = StdInfoFVC2.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                StdInfoFVC2.Close();

                rptrFields.DataSource = dtmainfields;
                rptrFields.DataBind();
                tvCategoryList.Nodes[0].Selected = true;
                tvStudent360.Nodes[1].Selected = true;
                lblHeader.Visible = true;
                lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                PopulateSummaryFields();
                lblstudentNo.Text = "1";
                if (lblstudentNo.Text == "1")
                {
                    lbtnPreviousStudent.Enabled = false;
                }
                lbtnFirstStudent.Enabled = false;
                mvFormLayout.ActiveViewIndex = 1;
            }
            catch { }
        }
        protected void lbtnLastStudent_Click(object sender, EventArgs e)
        {            
            try
            {
                lbtnFirstStudent.Enabled = true;
                if (lblTotalStudentOfSchool.Text != "1")
                {
                    lbtnPreviousStudent.Enabled = true;
                }
                else
                {
                    lbtnPreviousStudent.Enabled = false;
                }
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                OpenSISWCFServiceStudentInformationClient StdInfoL = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfoL.GetLastStudentIdBySchoolId(SchoolID);
                StdInfoL.Close();
                hdnStdId.Value = dt.Rows[0]["std_id"].ToString();
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                int CatId = 1;
                OpenSISWCFServiceStudentInformationClient StdInfoFVC3 = new OpenSISWCFServiceStudentInformationClient();
                DataTable dtmainfields = StdInfoFVC3.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                StdInfoFVC3.Close();

                rptrFields.DataSource = dtmainfields;
                rptrFields.DataBind();
                tvCategoryList.Nodes[0].Selected = true;
                tvStudent360.Nodes[1].Selected = true;
                lblHeader.Visible = true;
                lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                PopulateSummaryFields();
                lblstudentNo.Text = lblTotalStudentOfSchool.Text;
                lbtnNextStudent.Enabled = false;
                lbtnLastStudent.Enabled = false;
                mvFormLayout.ActiveViewIndex = 1;
            }
            catch { }
        }

        protected void PopulateInSelectedNodeChange()
        {
            //StudentInfoBL StdInfo = new StudentInfoBL();
            //StudentBL schoolcategory = new StudentBL();
            //StudentSetupBL StSuBL = new StudentSetupBL();
            try
            {
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                int CatId = Convert.ToInt32("3");
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);

                OpenSISWCFServiceStudentInformationClient StdInfo1 = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfo1.getdefaultaddressfields(SchoolID, StudentID, Session["MLUICulture"].ToString());
                StdInfo1.Close();

                phAllFieldHolder.Controls.Clear();               
                int FieldId = 0;
                if (hdnCatId.Value.ToString() == "3")
                {
                    int Count = dTable.Rows.Count;
                    for (int k = Count - 1; k >= 0; k--)
                    {
                        this.dTable.Rows.RemoveAt(k);
                    }
                    hdnCatId.Value = "3";

                   // OpenSISWCFServiceStudentSetupClient schoolcategory = new OpenSISWCFServiceStudentSetupClient();
                    IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();


                    DataTable dtFields = schoolcategory.GetFieldsByCategoryStudentBusiness(SchoolID, CatId, Session["MLUICulture"].ToString());
                    schoolcategory.Close();

                    this.dTable.CellPadding = 3;
                    this.dTable.CellSpacing = 0;
                    this.dTable.Border = 0;
                    this.dTable.Width = "100%";
                    this.dTable.Attributes.Remove("class");
                    string[] SessionTable = AddTableList.Split(';');
                    int tRows;
                    int tCells = 2;
                    int tCellsmod = Convert.ToInt32(dtFields.Rows.Count % tCells);
                    int tCellsquotient = Convert.ToInt32(dtFields.Rows.Count / tCells);
                    if (tCellsmod != 0)
                    {
                        tCellsquotient = tCellsquotient + 1;
                        DataRow dr = dtFields.NewRow();
                        dtFields.Rows.Add(dr);
                    }
                    for (tRows = 0; tRows < tCellsquotient; tRows++)
                    {
                        int L = 0;
                        if (dtFields.Rows.Count > 0 || dtFields.Rows.Count != 0)
                        {
                            this.dTRow = new HtmlTableRow();
                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                this.dTCell = new HtmlTableCell();
                                this.dTCell2 = new HtmlTableCell();
                                dTCell2.Attributes.Add("class", "bevel_verline");
                                this.dTAdd = new HtmlTable();
                                this.dTAdd.CellPadding = 2;
                                this.dTAdd.CellSpacing = 0;
                                this.dTAdd.Border = 0;
                                this.dTAdd.Width = "100%";
                                DataTable dtaddressfields = null;
                                if (dtFields.Rows[L]["FieldName"].ToString() != "")
                                {
                                    dTCell.Align = "left";
                                    dTCell.VAlign = "top";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class=heading_bevelline>" + dtFields.Rows[L]["FieldName"].ToString() + "</div><div class=clear_m></div>";
                                    FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);
                                    //dtaddressfields = schoolcategory.GetAddressFieldsByFieldId();
                                    //StdInfo.FieldId = Convert.ToInt32(dtFields.Rows[L]["FieldId"]);

                                    OpenSISWCFServiceStudentInformationClient StdInfo2 = new OpenSISWCFServiceStudentInformationClient();
                                    dtaddressfields = StdInfo2.getaddressfieldvalues(SchoolID, FieldId, Session["MLUICulture"].ToString());
                                    StdInfo2.Close();

                                    int AddressTableRows;
                                    int AddressTableCells = 1;
                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);
                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                    if (AddressTableCellsmod != 0)
                                    {
                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                        int j = dtaddressfields.Rows.Count;
                                        DataRow dradd = dtaddressfields.NewRow();
                                        dtaddressfields.Rows.Add(dradd);
                                    }
                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                    {
                                        AddressTableRows = 0;
                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                        {
                                            this.dTAddRow = new HtmlTableRow();
                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                            {
                                                this.dTAddCell = new HtmlTableCell();
                                                this.dTAddCell1 = new HtmlTableCell();
                                                this.dTAddCell2 = new HtmlTableCell();
                                                this.dTAddCell.Align = "right";
                                                dTAddCell.Attributes.Add("class", "student_grid");
                                                this.dTAddCell.InnerHtml = "<div style='padding-left:0px;' class='blue_bold' >" + dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString() + "</div>";
                                                this.dTAddCell1.InnerHtml = " : ";
                                                dTAddCell.Align = "left";
                                                dTAddCell2.Align = "left";
                                                dTAddCell.VAlign = "top";
                                                dTAddCell1.VAlign = "top";
                                                dTAddCell2.VAlign = "top";
                                                dTAddCell.Attributes.Add("class", "width45");
                                                Label lbl = new Label();
                                                HiddenField hdnFieldAddr = new HiddenField();
                                                lbl.ID = "lbl" + FieldId;
                                                hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                                hdnFieldAddr.Value = dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() + "_" + dtaddressfields.Rows[AddressTableRows]["Default_Custom"].ToString() + "_" + dtFields.Rows[L]["FieldId"].ToString();
                                                this.dTAddCell2.Controls.Add(lbl);
                                                this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                                this.dTAddRow.Controls.Add(dTAddCell);
                                                this.dTAddRow.Controls.Add(dTAddCell1);
                                                this.dTAddRow.Controls.Add(dTAddCell2);
                                                dtaddressfields.Rows.RemoveAt(0);
                                                FieldId++;
                                            }
                                            AddressTableRows = 0;
                                            dTAdd.Controls.Add(dTAddRow);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    this.dTCell.Controls.Add(dTAdd);
                                    dtFields.Rows.RemoveAt(0);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }
                                }
                            }
                            this.dTable.Controls.Add(dTRow);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (SessionTable.Length > 1)
                    {
                        int SessionTableId = 1;
                        for (int i = 1; i < SessionTable.Length; i++)
                        {
                            this.dTRow = new HtmlTableRow();
                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                string sessionTab = "Address" + SessionTableId.ToString();
                                DataTable myArrayDataFromSession = (DataTable)Session[sessionTab];
                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");
                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    this.dTAdd.Width = "100%";
                                    //dTCell.Attributes.Add("class", "darkblue_content");
                                    this.dTCell.InnerHtml = "<div class=heading_bevelline>" + "Additional Contact" + "</div><div class=clear_m></div>";
                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {
                                        this.dTAddRow = new HtmlTableRow();
                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerHtml = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");
                                        Label lbl = new Label();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        lbl.ID = "lbl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(lbl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        FieldId++;
                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);
                                    }
                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }
                                    this.dTable.Controls.Add(dTRow);
                                }
                                SessionTableId++;
                            }
                        }
                    }
                    else
                    {
                        //StudentEditInfoBL stEditInfo = new StudentEditInfoBL();
                        //StudentBL stBL = new StudentBL();
                        //int SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                        // stBL.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                        //stEditInfo.CatId = Convert.ToInt32(hdnCatId.Value);
                        //stEditInfo.StudentID = Convert.ToInt32(hdnStdId.Value);
                        int HomeFieldId = 152;
                        int CheckCell = 0;
                        int RowNo = 0;

                        OpenSISWCFServiceStudentInformationClient stEditInfo = new OpenSISWCFServiceStudentInformationClient();
                        DataTable dtAddField = stEditInfo.GetAdditionalAddressContactSet(SchoolID,StudentID);
                        stEditInfo.Close();

                        int mod = dtAddField.Rows.Count % 2;
                        if (mod == 0)
                        {
                            RowNo = dtAddField.Rows.Count / 2;
                        }
                        else
                        {
                            RowNo = Convert.ToInt32(dtAddField.Rows.Count / 2) + 1;
                        }
                        for (int i = 0; i < RowNo; i++)
                        {
                            this.dTRow = new HtmlTableRow();
                            for (tCells = 0; tCells < 2; tCells++)
                            {
                                OpenSISWCFServiceStudentInformationClient StdInfoPAF = new OpenSISWCFServiceStudentInformationClient();
                                DataTable myArrayDataFromSession = StdInfoPAF.PopulateAdditionalField(SchoolID, HomeFieldId, Session["MLUICulture"].ToString());
                                StdInfoPAF.Close();
                                if (CheckCell == dtAddField.Rows.Count)
                                {
                                    myArrayDataFromSession = null;
                                }
                                if (myArrayDataFromSession != null)
                                {
                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");
                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    this.dTAdd.Width = "100%";
                                    string stringtranslted = DTL.Translate(dtAddField.Rows[CheckCell]["ContactName"].ToString(), "en", langto);
                                    this.dTCell.InnerHtml = "<div class=heading_bevelline>" + stringtranslted + "</div><div class=clear_m></div>";
                                    int AddressTableRows = 0;
                                    for (int m = 0; m < myArrayDataFromSession.Rows.Count; m++)
                                    {
                                        this.dTAddRow = new HtmlTableRow();
                                        this.dTAddCell = new HtmlTableCell();
                                        this.dTAddCell1 = new HtmlTableCell();
                                        this.dTAddCell2 = new HtmlTableCell();
                                        this.dTAddCell.Align = "right";
                                        dTAddCell.Attributes.Add("class", "student_grid");
                                        if (myArrayDataFromSession.Rows[m]["FieldName"].ToString() != "")
                                        {
                                            this.dTAddCell.InnerHtml = "<div class='blue_bold'>" + myArrayDataFromSession.Rows[m]["FieldName"].ToString() + "</div>";
                                            this.dTAddCell1.InnerHtml = " : ";
                                        }
                                        dTAddCell.Align = "left";
                                        dTAddCell2.Align = "left";
                                        dTAddCell.VAlign = "top";
                                        dTAddCell1.VAlign = "top";
                                        dTAddCell2.VAlign = "top";
                                        dTAddCell.Attributes.Add("class", "width45");
                                        Label lbl = new Label();
                                        HiddenField hdnFieldAddr = new HiddenField();
                                        lbl.ID = "lbl" + FieldId;
                                        hdnFieldAddr.ID = "hdnAddr" + FieldId;
                                        hdnFieldAddr.Value = myArrayDataFromSession.Rows[m]["FieldId"].ToString() + "_" + myArrayDataFromSession.Rows[m]["Default_Custom"].ToString();
                                        this.dTAddCell2.Controls.Add(lbl);
                                        this.dTAddCell2.Controls.Add(hdnFieldAddr);
                                        this.dTAddRow.Controls.Add(dTAddCell);
                                        this.dTAddRow.Controls.Add(dTAddCell1);
                                        this.dTAddRow.Controls.Add(dTAddCell2);
                                        FieldId++;
                                        AddressTableRows = 0;
                                        dTAdd.Controls.Add(dTAddRow);
                                    }
                                    this.dTCell.Controls.Add(dTAdd);
                                    this.dTRow.Controls.Add(this.dTCell);
                                    if (tCells == 0)
                                    {
                                        this.dTRow.Controls.Add(this.dTCell2);
                                    }
                                    this.dTable.Controls.Add(dTRow);
                                    CheckCell++;
                                }
                            }
                        }
                    }
                    phAllFieldHolder.Controls.Add(dTable);
                }
            }
            catch
            {
            }
        }
        protected void PopulateFieldData()
        {
            //StudentInfoBL StdInfo = new StudentInfoBL();
            try
            {
                DataTable dtUserData = new DataTable();
                dtUserData.Columns.Add("Value");
                dtUserData.Columns.Add("FieldId");
                dtUserData.Columns.Add("FieldCatagory");
                dtUserData.Columns.Add("Value1");
                dtUserData.Columns.Add("FieldId1");
                dtUserData.Columns.Add("FieldCatagory1");
                string PrevSessionTable = hdnCatId.Value.ToString();
                DataTable myArrayDataFromSession = (DataTable)Session[PrevSessionTable];
                if (myArrayDataFromSession != null)
                {
                    foreach (var C in phAllFieldHolder.Controls)
                    {
                        if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
                        {
                            HtmlTable dtFieldHolder = ((HtmlTable)C);
                            int TableRow = 0;
                            foreach (Control row in dtFieldHolder.Controls)
                            {
                                int TableCell = 0;
                                foreach (Control cell in row.Controls)
                                {
                                    foreach (Control Con in cell.Controls)
                                    {
                                        if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                                        {
                                            Label txtUserField = ((Label)Con);
                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                            TableCell = TableCell + 3;
                                        }
                                        if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                                        {
                                            HtmlTable dtAddFieldHolder = ((HtmlTable)Con);
                                            foreach (Control Addrow in dtAddFieldHolder.Controls)
                                            {
                                                int AddCellCount = 0;
                                                foreach (Control Addcell in Addrow.Controls)
                                                {
                                                    foreach (Control AddCon in Addcell.Controls)
                                                    {
                                                        if (TableRow <= myArrayDataFromSession.Rows.Count - 1)
                                                        {
                                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(Label)))
                                                            {
                                                                Label txtUserField = ((Label)AddCon);
                                                                txtUserField.Text = myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString();
                                                            }
                                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(CheckBoxList)))
                                                            {
                                                                CheckBoxList ChkUserField = ((CheckBoxList)AddCon);
                                                                TableRow--;
                                                            }
                                                        }
                                                    }
                                                }
                                                TableRow++;
                                            }
                                        }
                                    }
                                }
                                TableRow++;
                            }
                        }
                    }
                }
                else
                {
                    //StudentEditInfoBL StFieldValue = new StudentEditInfoBL();
                   
                    int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                    int CatId = Convert.ToInt32(hdnCatId.Value.ToString());
                    //StFieldValue.StudentID = Convert.ToInt32(hdnStdId.Value);
                    //StdInfo.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
                    //StdInfo.CatId = Convert.ToInt32(hdnCatId.Value.ToString());
                    int StudentID = Convert.ToInt32(hdnStdId.Value);

                    if (hdnCatId.Value.ToString() != "3")
                    {
                        OpenSISWCFServiceStudentInformationClient StFieldValue = new OpenSISWCFServiceStudentInformationClient();
                        DataTable dtFieldvalue = StFieldValue.PopulateFieldValue(CatId,SchoolID,StudentID);
                        StFieldValue.Close();

                        DataRow drf = dtUserData.NewRow();
                        dtUserData.Rows.Add(drf);
                        for (int i = 0; i < dtFieldvalue.Rows.Count; i = i + 2)
                        {
                            DataRow dr = dtUserData.NewRow();
                            if (i % 2 == 0)
                            {
                                dr["Value"] = dtFieldvalue.Rows[i]["value"].ToString();
                                dr["FieldId"] = dtFieldvalue.Rows[i]["field_id"].ToString();
                                dr["FieldCatagory"] = dtFieldvalue.Rows[i]["field_category"].ToString();
                                if (i + 1 < dtFieldvalue.Rows.Count)
                                {
                                    dr["Value1"] = dtFieldvalue.Rows[i + 1]["value"].ToString();
                                    dr["FieldId1"] = dtFieldvalue.Rows[i + 1]["field_id"].ToString();
                                    dr["FieldCatagory1"] = dtFieldvalue.Rows[i + 1]["field_category"].ToString();
                                }
                                else
                                {
                                    dr["Value1"] = "";
                                    dr["FieldId1"] = "";
                                    dr["FieldCatagory1"] = "";
                                }
                                dtUserData.Rows.Add(dr);
                            }
                        }
                        DataRow drl = dtUserData.NewRow();
                        dtUserData.Rows.Add(drl);
                        myArrayDataFromSession = dtUserData;
                    }
                    else
                    {
                        //DataTable dtAddressField = StFieldValue.PopulateAddressFields();

                        OpenSISWCFServiceStudentInformationClient StdInfoPAF = new OpenSISWCFServiceStudentInformationClient();
                        DataTable dtAddressField = StdInfoPAF.PopulateAddressFields(SchoolID,StudentID,CatId);
                        StdInfoPAF.Close();

                        myArrayDataFromSession = dtAddressField;
                    }
                    foreach (var C in phAllFieldHolder.Controls)
                    {
                        if (object.ReferenceEquals(C.GetType(), typeof(HtmlTable)))
                        {
                            HtmlTable dtFieldHolder = ((HtmlTable)C);
                            int TableRow = 0;
                            foreach (Control row in dtFieldHolder.Controls)
                            {
                                int TableCell = 0;
                                int tablecount = 0;
                                foreach (Control cell in row.Controls)
                                {
                                    foreach (Control Con in cell.Controls)
                                    {
                                        if (object.ReferenceEquals(Con.GetType(), typeof(Label)))
                                        {
                                            Label txtUserField = ((Label)Con);
                                            txtUserField.Text = myArrayDataFromSession.Rows[TableRow][TableCell].ToString();
                                            TableCell = TableCell + 3;
                                        }
                                        if (object.ReferenceEquals(Con.GetType(), typeof(HtmlTable)))
                                        {
                                            HtmlTable dtAddFieldHolder = ((HtmlTable)Con);
                                            tablecount = tablecount + 1;
                                            foreach (Control Addrow in dtAddFieldHolder.Controls)
                                            {
                                                int AddCellCount = 0;
                                                foreach (Control Addcell in Addrow.Controls)
                                                {
                                                    foreach (Control AddCon in Addcell.Controls)
                                                    {
                                                        if (TableRow <= myArrayDataFromSession.Rows.Count - 1)
                                                        {
                                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(Label)))
                                                            {
                                                                Label txtUserField = ((Label)AddCon);
                                                                txtUserField.Text = myArrayDataFromSession.Rows[TableRow][AddCellCount++].ToString();
                                                                //--------------------------------------------------state/contact rel(default)--------------------------------
                                                                if (myArrayDataFromSession.Rows[TableRow][2].ToString() == "D")
                                                                {
                                                                    if (myArrayDataFromSession.Rows[TableRow][1].ToString() == "4" || myArrayDataFromSession.Rows[TableRow][1].ToString() == "13" || myArrayDataFromSession.Rows[TableRow][1].ToString() == "24" || myArrayDataFromSession.Rows[TableRow][1].ToString() == "40")
                                                                    {
                                                                        string State = txtUserField.Text.ToString().Trim();
                                                                        OpenSISWCFServiceStudentInformationClient StdInfoGSN = new OpenSISWCFServiceStudentInformationClient();
                                                                        DataTable dtstate = StdInfoGSN.GetStateName(State);
                                                                        StdInfoGSN.Close();
                                                                        if (dtstate.Rows.Count > 0)
                                                                        {
                                                                            txtUserField.Text = dtstate.Rows[0]["NAME"].ToString();
                                                                        }
                                                                        else
                                                                        {
                                                                            txtUserField.Text = "";
                                                                        }
                                                                    }
                                                                    if (myArrayDataFromSession.Rows[TableRow][1].ToString() == "15" || myArrayDataFromSession.Rows[TableRow][1].ToString() == "31")
                                                                    {
                                                                        string PersonRelId = txtUserField.Text.ToString().Trim();

                                                                        OpenSISWCFServiceStudentInformationClient StdInfoCRel = new OpenSISWCFServiceStudentInformationClient();
                                                                        DataTable dtpersonrelname = StdInfoCRel.getcontactrelationshipname(PersonRelId);
                                                                        StdInfoCRel.Close();
                                                                        if (dtpersonrelname.Rows.Count > 0)
                                                                        {
                                                                            txtUserField.Text = dtpersonrelname.Rows[0]["person_stu_rel_type_nm"].ToString();
                                                                        }
                                                                        else
                                                                        {
                                                                            txtUserField.Text = "";
                                                                        }
                                                                    }

                                                                }
                                                                //--------------------------------------------------state/contact rel--------------------------------

                                                                //--------------------------------------------------state/contact rel(additional)-----------------------

                                                                if (myArrayDataFromSession.Rows[TableRow][2].ToString() == "C")
                                                                {
                                                                    if (myArrayDataFromSession.Rows[TableRow][1].ToString() == "1")
                                                                    {
                                                                        if (isNumeric(txtUserField.Text.ToString().Trim(), System.Globalization.NumberStyles.Integer))
                                                                        {
                                                                            string PersonRelId = txtUserField.Text.ToString().Trim();

                                                                            OpenSISWCFServiceStudentInformationClient StdInfoCRel1 = new OpenSISWCFServiceStudentInformationClient();
                                                                            DataTable dtpersonrelname = StdInfoCRel1.getcontactrelationshipname(PersonRelId);
                                                                            StdInfoCRel1.Close();
                                                                            if (dtpersonrelname.Rows.Count > 0)
                                                                            {
                                                                                txtUserField.Text = dtpersonrelname.Rows[0]["person_stu_rel_type_nm"].ToString();
                                                                            }
                                                                            else
                                                                            {
                                                                                txtUserField.Text = "";
                                                                            }
                                                                        }
                                                                    }
                                                                    if (myArrayDataFromSession.Rows[TableRow][1].ToString() == "4")
                                                                    {
                                                                        if (isNumeric(txtUserField.Text.ToString().Trim(), System.Globalization.NumberStyles.Integer))
                                                                        {
                                                                            string State = txtUserField.Text.ToString().Trim();

                                                                            OpenSISWCFServiceStudentInformationClient StdInfoSNM = new OpenSISWCFServiceStudentInformationClient();
                                                                            DataTable dtstate = StdInfoSNM.GetStateName(State);
                                                                            StdInfoSNM.Close();
                                                                            if (dtstate.Rows.Count > 0)
                                                                            {
                                                                                txtUserField.Text = dtstate.Rows[0]["NAME"].ToString();
                                                                            }
                                                                            else
                                                                            {
                                                                                txtUserField.Text = "";
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                //--------------------------------------------------state/contact rel(additional)-----------------------
                                                            }
                                                            if (object.ReferenceEquals(AddCon.GetType(), typeof(CheckBoxList)))
                                                            {
                                                                CheckBoxList ChkUserField = ((CheckBoxList)AddCon);
                                                                TableRow--;
                                                            }
                                                        }
                                                    }
                                                }
                                                TableRow++;
                                            }
                                            if (tablecount % 2 == 0)
                                            {
                                                TableRow--;
                                            }
                                        }
                                    }
                                }
                                TableRow++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string Ex = ex.ToString();
            }
        }
        public bool isNumeric(string val, System.Globalization.NumberStyles NumberStyle)
        {
            Double result;
            return Double.TryParse(val, NumberStyle,System.Globalization.CultureInfo.CurrentCulture, out result);
        }
        //protected void gvStudentList_RowCommand(object sender, GridViewCommandEventArgs e)
        //{
        //    StudentInfoBL StdInfo = new StudentInfoBL();
        //    if (e.CommandName == "ShowStdInfo")
        //    {

        //        string stdid = e.CommandArgument.ToString();
        //        hdnStdId.Value = stdid;
        //        StdInfo.StudentID = Convert.ToInt32(hdnStdId.Value);
        //        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //        StdInfo.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        StdInfo.CatId = 1;
        //        DataTable dt = StdInfo.GetFieldValueByCategory();
        //        rptrFields.DataSource = dt;
        //        rptrFields.DataBind();
        //        tvCategoryList.Nodes[0].Selected = true;
        //        tvStudent360.Nodes[1].Selected = true;
        //        PopulateSummaryFields();


        //        GridViewRow selectedRow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
        //        int rowIndex = selectedRow.RowIndex;
        //        lblstudentNo.Text = (rowIndex + 1).ToString();
        //        lblTotalStudentOfSchool.Text = (gvStudentList.Rows.Count).ToString();
        //        if (lblstudentNo.Text == lblTotalStudentOfSchool.Text)
        //        {
        //            lbtnLastStudent.Enabled = false;
        //            lbtnNextStudent.Enabled = false;
        //        }
        //        if (lblstudentNo.Text == "1")
        //        {
        //            lbtnPreviousStudent.Enabled = false;
        //            lbtnFirstStudent.Enabled = false;
        //        }
        //        mvMain.ActiveViewIndex = 1;
        //    }
        //}
        protected void gvStudentList_ItemCommand(object sender, ReorderListCommandEventArgs e)
        {
           // StudentInfoBL StdInfo = new StudentInfoBL();
            if (e.CommandName == "ShowStdInfo")
            {
                string stdid = e.CommandArgument.ToString();
                hdnStdId.Value = stdid;
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                int CatId = 1;
                OpenSISWCFServiceStudentInformationClient StdInfogFVBC = new OpenSISWCFServiceStudentInformationClient();
                DataTable dt = StdInfogFVBC.GetFieldValueByCategory(SchoolID, StudentID, CatId, Session["MLUICulture"].ToString());
                StdInfogFVBC.Close();

                rptrFields.DataSource = dt;
                rptrFields.DataBind();
                tvCategoryList.Nodes[0].Selected = true;
                lblHeader.Visible = true;
                lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                tvStudent360.Nodes[1].Selected = true;
                PopulateSummaryFields();
                int itemindex = e.Item.ItemIndex;
                lblstudentNo.Text = (itemindex + 1).ToString();
                lblTotalStudentOfSchool.Text = (gvStudentList.Items.Count).ToString();
                if (lblstudentNo.Text == lblTotalStudentOfSchool.Text)
                {
                    lbtnLastStudent.Enabled = false;
                    lbtnNextStudent.Enabled = false;
                }
                if (lblstudentNo.Text == "1")
                {
                    lbtnPreviousStudent.Enabled = false;
                    lbtnFirstStudent.Enabled = false;
                }
                mvMain.ActiveViewIndex = 1;
            }
        }
        protected void ibtnEdit_Click(object sender, ImageClickEventArgs e)
        {
            //StudentInfoBL StdInfo = new StudentInfoBL();
            for (int i = 0; i < gvStudentList.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)gvStudentList.Items[i].FindControl("chk");
                HiddenField hdnStudentId = (HiddenField)gvStudentList.Items[i].FindControl("hdnStudentId");
                if (chk.Checked)
                {
                    Response.Redirect("EditStudentInfo.aspx?studentid=" + hdnStudentId.Value + "");
                }
            }
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {
            //Function Func = new Function();
            //try
            //{
            //    Func.ResetFormControlValues(this.Page);
            //}
            //catch { }
            //finally
            //{
            //    Func = null;
            //}
        }
        public void PopulateMLUI()
        {
            if (System.Web.HttpContext.Current.Session["MLUICulture"].ToString() != "en")
            {
                ltrlsearstud.Text = DTL.Translate(ltrlsearstud.Text, "en", langto);
                Literal1.Text = DTL.Translate(Literal1.Text, "en", langto);
                Literal2.Text = DTL.Translate(Literal2.Text, "en", langto);
                Literal3.Text = DTL.Translate(Literal3.Text, "en", langto);
                Literal4.Text = DTL.Translate(Literal4.Text, "en", langto);
                Literal5.Text = DTL.Translate(Literal5.Text, "en", langto);
                Literal6.Text = DTL.Translate(Literal6.Text, "en", langto);
                Literal7.Text = DTL.Translate(Literal7.Text, "en", langto);
                btnSearch.Text = DTL.Translate(btnSearch.Text, "en", langto);
                btnReset.Text = DTL.Translate(btnReset.Text, "en", langto);
                Literal8.Text = DTL.Translate(Literal8.Text, "en", langto);
                Literal9.Text = DTL.Translate(Literal9.Text, "en", langto);
                Literal10.Text = DTL.Translate(Literal10.Text, "en", langto);
                Literal11.Text = DTL.Translate(Literal11.Text, "en", langto);
                Literal12.Text = DTL.Translate(Literal12.Text, "en", langto);
                Literal13.Text = DTL.Translate(Literal13.Text, "en", langto);
            }
        }
        protected DataTable PopulateVacciGrid()
        {  
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStdId.Value);

            OpenSISWCFServiceStudentInformationClient StdInfoGVcc = new OpenSISWCFServiceStudentInformationClient();
            DataTable dt = StdInfoGVcc.GetVaccinationFieldValue(SchoolID,StudentID);
            StdInfoGVcc.Close();
            DataTable dtVaccinationDetails = new DataTable();
            dtVaccinationDetails.Columns.Add("Vaccination_Code");
            dtVaccinationDetails.Columns.Add("Vaccination_Name");
            dtVaccinationDetails.Columns.Add("Vaccination_Date");
            dtVaccinationDetails.Columns.Add("Vaccination_Expiry_Date");
            dtVaccinationDetails.Columns.Add("Waiver");
            int j = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i % 5 == 0)
                {
                    drvacc = dtVaccinationDetails.NewRow();
                    j = 0;
                    dtVaccinationDetails.Rows.Add(drvacc);
                }
                drvacc[j] = dt.Rows[i][3];
                j++;
            }
            return dtVaccinationDetails;

        }
        protected void GVImmunization_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblImmutype = (Label)e.Row.FindControl("lblImmunizationType");
                if (lblImmutype.Text.ToString() == "1")
                {
                    lblImmutype.Text = "Imunization";
                }
                if (lblImmutype.Text.ToString() == "2")
                {
                    lblImmutype.Text = "Physical";
                }
                if (lblImmutype.Text.ToString() == "0")
                {
                    lblImmutype.Text = "";
                }
            }
        }
        protected void rptrSchlInfo_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //StudentInfoBL StdInfo = new StudentInfoBL();
            try
            {                
                int SchoolID = Convert.ToInt32(Session["SchoolID"]);
                //InstallationBL INBL = new InstallationBL();
                HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
                HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
                HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
                Label lblValue = (Label)e.Item.FindControl("lblValue");
                Label lblFieldName = (Label)e.Item.FindControl("lblFieldName");
                HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
                HiddenField hdnCatId = (HiddenField)e.Item.FindControl("hdnCatId");
                int FieldId = Convert.ToInt32(hdnFieldId.Value);
                int StudentID = Convert.ToInt32(hdnStdId.Value);
                if (hdnDefCus.Value.ToString().Trim() == "D")
                {
                    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 5 || Convert.ToInt32(hdnFieldId.Value) == 7 || Convert.ToInt32(hdnFieldId.Value) == 109 || Convert.ToInt32(hdnFieldId.Value) == 174 || Convert.ToInt32(hdnFieldId.Value) == 6)
                    {
                        e.Item.Visible = false;
                    }
                    if (Convert.ToInt32(hdnFieldId.Value) == 106)
                    {
                        if (lblValue.Text.ToString() != "")
                        {
                            if (lblValue.Text.ToString() == "Y")
                            {
                                lblValue.Text = "Yes";
                            }
                            else
                            {
                                lblValue.Text = "No";
                            }
                        }
                    }
                }
                if (hdnDefCus.Value.ToString().Trim() == "C")
                {
                    //if (lblValue.Text.ToString() != "" || lblValue.Text.ToString() != "0")
                    //{
                    //    StdInfo.ExtrafieldId = Convert.ToInt32(hdnFieldId.Value);
                    //    StdInfo.ListItemId = Convert.ToInt32(lblValue.Text.ToString());
                    //    lblValue.Text = StdInfo.GetdynamicallycreatedDataItems();
                    //}
                    if (lblValue.Text.ToString() != "")
                    {
                        int ExtrafieldId = Convert.ToInt32(hdnFieldId.Value);
                        int ListItemId = Convert.ToInt32(lblValue.Text.ToString());
                        OpenSISWCFServiceStudentInformationClient StdInfoGDCDI = new OpenSISWCFServiceStudentInformationClient();
                        lblValue.Text = StdInfoGDCDI.GetdynamicallycreatedDataItems(ExtrafieldId,ListItemId);
                        StdInfoGDCDI.Close();
                    }
                }
            }
            catch
            {
            }
        }
        protected void gvEnrInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            SISInstall SISinstall = new SISInstall();
            OpenSISWCFServiceInstallationClient InstallBL = new OpenSISWCFServiceInstallationClient();
            DataTable dtDateFormat = InstallBL.getdateformat();
            InstallBL.Close();

            if (dtDateFormat.Rows.Count > 0)
            {
                SISinstall.CalenderDateFormat = dtDateFormat.Rows[0][0].ToString();
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblAttStrtDate = (Label)e.Row.FindControl("lblAttStrtDate");
                Label lblExitDate = (Label)e.Row.FindControl("lblExitDate");
                //CheckBox chk = (CheckBox)e.Row.FindControl("chk");
                //Label lblPrimryCert = (Label)e.Row.FindControl("lblPrimryCert");
                if (lblAttStrtDate.Text != "")
                {
                   // DateTime certdate = DateTime.Parse(lblAttStrtDate.Text,System.Globalization.DateTimeFormatInfo.InvariantInfo);
                   // DateTime certdate = Convert.ToDateTime(lblAttStrtDate.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                   // lblAttStrtDate.Text = certdate.Date.ToString(SISinstall.CalenderDateFormat);
                }
                if (lblExitDate.Text != "")
                {
                    //string ss = System.Globalization.DateTimeFormatInfo.InvariantInfo.ShortDatePattern;
                    //DateTime CertExpDate = DateTime.Parse(lblExitDate.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                   // DateTime dt;
                    
                   //  dt = Convert.ToDateTime(lblExitDate.Text).ToString("MM-dd-yyyy");
;
                    //DateTime dt1 = DateTime.ParseExact(lblExitDate.Text, "MM/dd/yyyy", SISinstall.CalenderDateFormat); 
                    //DateTime CertExpDate = Convert.ToDateTime(lblExitDate.Text, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    //lblExitDate.Text = CertExpDate.Date.ToString(SISinstall.CalenderDateFormat);
                }
            }
        }

        //-----------------------  Cancel  -----------------------
        protected void rptrSpecEdu_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //StudentBL schoolcategory = new StudentBL();
            //try
            //{
            //    // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            //    //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            //    //hdnInitialCatId.Value = hdnCatId.Value;
            //    //schoolcategory.CatId = Convert.ToInt32(hdnCatId.Value);
            //    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //    //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
            //    //HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            //    //HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            //    //HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            //    //HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            //    //Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");
            //    //DataTable dtspec = schoolcategory.PopulateSpecialField();
            //    //for (int i = 0; i < dtspec.Rows.Count; i++)
            //    //{
            //    //    if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
            //    //    {
            //    //        lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
            //    //    }
            //    //}

            //}
            //catch { }

        }
        protected void rptrGiftProg_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //StudentBL schoolcategory = new StudentBL();
            //try
            //{
            //    // ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
            //    //EntryFormLayoutBL categoryfields = new EntryFormLayoutBL();
            //    //hdnInitialCatId.Value = hdnCatId.Value;
            //    //schoolcategory.CatId = Convert.ToInt32(hdnCatId.Value);
            //    //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
            //    //schoolcategory.SchoolID = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
            //    //HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            //    //HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            //    //HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
            //    //HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
            //    //Label lblfldnam = (Label)e.Item.FindControl("lblfldnam");
            //    //DataTable dtspec = schoolcategory.PopulateGiftField();
            //    //for (int i = 0; i < dtspec.Rows.Count; i++)
            //    //{
            //    //    if (hdnFieldId.Value.ToString() == dtspec.Rows[i]["FieldId"].ToString())
            //    //    {
            //    //        lblfldnam.Text = dtspec.Rows[i]["FieldName"].ToString();
            //    //    }
            //    //}

            //}
            //catch { }
        }
        //--------------------- Cancel ----------------------------

        public void PopulateSpecialValue()
        {            
            int CatId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStdId.Value);
            OpenSISWCFServiceStudentInformationClient StuInfoGSV = new OpenSISWCFServiceStudentInformationClient();
            DataTable dtspecial = StuInfoGSV.GetSpecialValues(SchoolID,StudentID,CatId);
            StuInfoGSV.Close();
            if (dtspecial.Rows.Count > 0)
            {
                rptrSpecEdu.DataSource = dtspecial;
                rptrSpecEdu.DataBind();
            }
        }
        public void PopulateGiftValue()
        {            
            int CatId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
            int SchoolID = Convert.ToInt32(Session["SchoolID"]);
            int StudentID = Convert.ToInt32(hdnStdId.Value);
            OpenSISWCFServiceStudentInformationClient StuInfoGGV = new OpenSISWCFServiceStudentInformationClient();
            DataTable dtGift = StuInfoGGV.GetGiftedValues(SchoolID,StudentID,CatId);
            StuInfoGGV.Close();
            if (dtGift.Rows.Count > 0)
            {
                rptrGiftProg.DataSource = dtGift;
                rptrGiftProg.DataBind();
            }
        }

        protected void rptrVccination_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
        }

        public void PopulateVccinationValue()
        {


                IopenSISServiceStudentClient schoolcategory = new IopenSISServiceStudentClient();
                DataTable dtVcea = new DataTable();
                dtVcea = schoolcategory.GetVaccinationFieldsValue(Convert.ToInt32(Session["SchoolID"]), Convert.ToInt32(hdnStdId.Value));

                //(DataTable)Session["SpecialGiftForInsert"] = dtGift;
                if (dtVcea.Rows.Count > 0)
                {
                    rptrVccination.DataSource = dtVcea;
                    rptrVccination.DataBind();
                    schoolcategory.Close();
                    
                }
           
        }
    }
}